using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
	/// <summary>
	/// Strongly-typed collection for the Approval class.
	/// </summary>
    [Serializable]
	public partial class ApprovalCollection : ActiveList<Approval, ApprovalCollection>
	{	   
		public ApprovalCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>ApprovalCollection</returns>
		public ApprovalCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Approval o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the Approval table.
	/// </summary>
	[Serializable]
	public partial class Approval : ActiveRecord<Approval>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Approval()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Approval(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Approval(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Approval(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Approval", TableType.Table, DataService.GetInstance("BookShop"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarApprovalID = new TableSchema.TableColumn(schema);
				colvarApprovalID.ColumnName = "ApprovalID";
				colvarApprovalID.DataType = DbType.AnsiStringFixedLength;
				colvarApprovalID.MaxLength = 20;
				colvarApprovalID.AutoIncrement = false;
				colvarApprovalID.IsNullable = false;
				colvarApprovalID.IsPrimaryKey = true;
				colvarApprovalID.IsForeignKey = false;
				colvarApprovalID.IsReadOnly = false;
				colvarApprovalID.DefaultSetting = @"";
				colvarApprovalID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApprovalID);
				
				TableSchema.TableColumn colvarApprovalAdvise = new TableSchema.TableColumn(schema);
				colvarApprovalAdvise.ColumnName = "ApprovalAdvise";
				colvarApprovalAdvise.DataType = DbType.String;
				colvarApprovalAdvise.MaxLength = 50;
				colvarApprovalAdvise.AutoIncrement = false;
				colvarApprovalAdvise.IsNullable = true;
				colvarApprovalAdvise.IsPrimaryKey = false;
				colvarApprovalAdvise.IsForeignKey = false;
				colvarApprovalAdvise.IsReadOnly = false;
				colvarApprovalAdvise.DefaultSetting = @"";
				colvarApprovalAdvise.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApprovalAdvise);
				
				TableSchema.TableColumn colvarAdviser = new TableSchema.TableColumn(schema);
				colvarAdviser.ColumnName = "Adviser";
				colvarAdviser.DataType = DbType.AnsiStringFixedLength;
				colvarAdviser.MaxLength = 10;
				colvarAdviser.AutoIncrement = false;
				colvarAdviser.IsNullable = false;
				colvarAdviser.IsPrimaryKey = true;
				colvarAdviser.IsForeignKey = false;
				colvarAdviser.IsReadOnly = false;
				colvarAdviser.DefaultSetting = @"";
				colvarAdviser.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdviser);
				
				TableSchema.TableColumn colvarApprovalDate = new TableSchema.TableColumn(schema);
				colvarApprovalDate.ColumnName = "ApprovalDate";
				colvarApprovalDate.DataType = DbType.DateTime;
				colvarApprovalDate.MaxLength = 0;
				colvarApprovalDate.AutoIncrement = false;
				colvarApprovalDate.IsNullable = true;
				colvarApprovalDate.IsPrimaryKey = false;
				colvarApprovalDate.IsForeignKey = false;
				colvarApprovalDate.IsReadOnly = false;
				colvarApprovalDate.DefaultSetting = @"";
				colvarApprovalDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApprovalDate);
				
				TableSchema.TableColumn colvarResult = new TableSchema.TableColumn(schema);
				colvarResult.ColumnName = "Result";
				colvarResult.DataType = DbType.Boolean;
				colvarResult.MaxLength = 0;
				colvarResult.AutoIncrement = false;
				colvarResult.IsNullable = true;
				colvarResult.IsPrimaryKey = false;
				colvarResult.IsForeignKey = false;
				colvarResult.IsReadOnly = false;
				colvarResult.DefaultSetting = @"";
				colvarResult.ForeignKeyTableName = "";
				schema.Columns.Add(colvarResult);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["BookShop"].AddSchema("Approval",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("ApprovalID")]
		[Bindable(true)]
		public string ApprovalID 
		{
			get { return GetColumnValue<string>(Columns.ApprovalID); }
			set { SetColumnValue(Columns.ApprovalID, value); }
		}
		  
		[XmlAttribute("ApprovalAdvise")]
		[Bindable(true)]
		public string ApprovalAdvise 
		{
			get { return GetColumnValue<string>(Columns.ApprovalAdvise); }
			set { SetColumnValue(Columns.ApprovalAdvise, value); }
		}
		  
		[XmlAttribute("Adviser")]
		[Bindable(true)]
		public string Adviser 
		{
			get { return GetColumnValue<string>(Columns.Adviser); }
			set { SetColumnValue(Columns.Adviser, value); }
		}
		  
		[XmlAttribute("ApprovalDate")]
		[Bindable(true)]
		public DateTime? ApprovalDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.ApprovalDate); }
			set { SetColumnValue(Columns.ApprovalDate, value); }
		}
		  
		[XmlAttribute("Result")]
		[Bindable(true)]
		public bool? Result 
		{
			get { return GetColumnValue<bool?>(Columns.Result); }
			set { SetColumnValue(Columns.Result, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varApprovalID,string varApprovalAdvise,string varAdviser,DateTime? varApprovalDate,bool? varResult)
		{
			Approval item = new Approval();
			
			item.ApprovalID = varApprovalID;
			
			item.ApprovalAdvise = varApprovalAdvise;
			
			item.Adviser = varAdviser;
			
			item.ApprovalDate = varApprovalDate;
			
			item.Result = varResult;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varApprovalID,string varApprovalAdvise,string varAdviser,DateTime? varApprovalDate,bool? varResult)
		{
			Approval item = new Approval();
			
				item.ApprovalID = varApprovalID;
			
				item.ApprovalAdvise = varApprovalAdvise;
			
				item.Adviser = varAdviser;
			
				item.ApprovalDate = varApprovalDate;
			
				item.Result = varResult;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn ApprovalIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ApprovalAdviseColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn AdviserColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn ApprovalDateColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn ResultColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ApprovalID = @"ApprovalID";
			 public static string ApprovalAdvise = @"ApprovalAdvise";
			 public static string Adviser = @"Adviser";
			 public static string ApprovalDate = @"ApprovalDate";
			 public static string Result = @"Result";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
